package com.csf.controller;

import com.csf.service.DateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;

@Controller
public class DateController {

    @Autowired
    private DateService dateService;

    @RequestMapping(path = "/data",method = {RequestMethod.GET,RequestMethod.POST})
    public String getData(){
        return "/site/admin/data";
    }

//   统计访问量
    @RequestMapping(path = "/totalua",method = RequestMethod.POST)
    public String getTotalUA(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, Model model){
        long ua = dateService.selectUV(start, end);
        model.addAttribute("tua",ua);
        model.addAttribute("tstart",start);
        model.addAttribute("tend",end);
        return "forward:/data";
    }
//   统计签到数量
    @RequestMapping(path = "/getdua",method = RequestMethod.POST)
    public String getTotaldua(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, Model model){
        long dua = dateService.selectDAU(start, end);
        model.addAttribute("dua",dua);
        model.addAttribute("dstart",start);
        model.addAttribute("dend",end);
        return "forward:/data";
    }
}
